<?php
/**
 * @Author: Awe
 * @Date:   2018-04-18 11:25:41
 * @Last Modified by:   Awe
 * @Last Modified time: 2018-04-18 11:36:44
 */
class QiniuController extends CenterController {
    public function init() {
        $this->NotLoginExclusion = ["token"] ;
        $this->NotAuthExclusion=["token"];
        parent::init();
    }
    public function tokenAction(){
        global $_G;
        $AccessKey = $_G['config']['qiniu']['qiniu']['AccessKey'];
        $SecretKey = $_G['config']['qiniu']['qiniu']['SecretKey'];
        $data['scope']='bird';
        $data['deadline']=time()+3600;
        $encoded=$this->urlsafe_base64_encode(json_encode($data));
        $signature=hash_hmac('sha1',$encoded,$SecretKey ,true);
        $encode_signed = $this->urlsafe_base64_encode($signature);
        $UploadToken=$AccessKey . ':'.$encode_signed.':'.$encoded;
        echo json_encode(array("uptoken" => $UploadToken));
    }
    private function urlsafe_base64_encode($data)
    {
        $find = array('+', '/');
        $replace = array('-', '_');
        return str_replace($find, $replace, base64_encode($data));
    }
}